package com.hwd.gmall.seckill.listener;

import com.hwd.gmall.common.aspect.ListenMessage;
import com.hwd.gmall.common.constant.PaymentConst;
import com.hwd.gmall.seckill.service.SeckillOrderService;
import com.rabbitmq.client.Channel;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 监听秒杀订单支付的消息的消费者
 *
 * @author 黄伟东/Victor
 * @date 2022/5/13 0:44
 */
@Component
@Log4j2
public class SeckillOrderPayMessageListener {

    @Resource
    private SeckillOrderService seckillOrderService;

    /**
     * 修改秒杀订单支付后的状态
     *
     * @param message 消息体
     * @param ignoredChannel 连接
     */
    @RabbitListener(queues = PaymentConst.SECKILL_ORDER_PAY_QUEUE)
    @ListenMessage(messageDescription = "秒杀订单支付后修改状态的信息")
    public void seckillOrderPayMessage(Message message, Channel ignoredChannel) {
        // 修改秒杀订单
        seckillOrderService.updateSeckillOrder(new String(message.getBody()));
    }
}
